package demo01;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-11
 * Time: 18:59
 */
class Cat implements Cloneable{
    private String name = "mimi";
    private int age = 15;
    Sound s = new Sound();

    public String getName() {
        return name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Cat temp = (Cat)super.clone();
        temp.s = (Sound) this.s.clone();
        return temp;
    }
}

class Sound implements Cloneable{
    double money = 10.5;

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

}
public class Test01 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Cat cat1 = new Cat();
        Cat cat2;
        cat2 = (Cat)cat1.clone();
        cat2.s.money = 90.5;
        System.out.println( cat1.s.money);
        System.out.println( cat2.s.money);
    }
}
